home *** CD-ROM | disk | FTP | other *** search
- /* Program EX_0506.C
- Listing 11C - see documentation in TUTOR.SSS
- */
-
- #include <conio.h>
- #include "SSSC.H"
-
- #define ARRIVL 1
- #define STARTA 2
- #define ENDACT 3
- #define NEXTAC 4
-
- #define FINAL 3
-
- #define YES 1
- #define NO 0
-
- int busy[3] = { NO, NO, NO };
- int block[3] = { NO, NO, NO };
- double defect[3] = { .3, .2, .1 };
- int ecode, statn, rewkn, debugf;
- double serial;
-
- void prime()
- {
- debugf = 0;
- serial = 1.0;
- INIQUE(3, 2, 3);
- INISTA(1, "Prod t #1", 0, 0, 0/0, 0.0);
- INISTA(2, "Prod t #2", 0, 0, 0.0, 0.0);
- INISTA(3, "Prod t #3", 0, 0, 0.0, 0.0);
- CREATE(0.0, 0);
- SIMEND(6.0);
- }
-
- void deciph(i)
- int i;
- {
- statn = i & 3;
- rewkn = i >> 2;
- }
-
- void triggr(i)
- int i;
- {
- REMVFQ(i, 1);
- SCHED(0, NEXTAC, IDE());
- if (i > 1) CREATE(0.0, i - 1);
- }
-
- void unblk(statn)
- int statn;
- {
- DISPOS();
- if (block[statn])
- {
- if ((NQ(statn)) && (busy[statn] == NO))
- triggr(statn);
- block[statn] = NO;
- }
- }
-
- main()
- {
- prime();
- do
- {
- if ((ecode = NEXTEV()) > 0)
- switch(ecode)
- {
-
- case ARRIVL:
- if (IDE() > 0) unblk(IDE()); else
- {
- CREATE(EX(0.5), 0);
- SETA(1, RN(0.25, 0.05));
- SETA(2, serial);
- serial++;
- SCHED(0, NEXTAC, 1);
- }
- break;
-
- case NEXTAC:
- deciph(IDE());
- if (debugf) printf(
- "At%6.2f#%2.0ffor%4.2fh.to station # %d for %d rework",
- T(), A(2), A(1), statn, rewkn);
-
- if (busy[statn] || block[statn])
- {
- QUEUE(statn, 0.0);
- if (debugf) printf(" and waits\n");
- if ((NQ(statn) > 4) && (statn > 1))
- block[statn - 1] = YES;
- } else
-
- {
- SCHED(0.0, STARTA, IDE());
- if (debugf)
- {
- printf(" and processed\n");
- if(toupper(getch())== 'Q') exit(1);
- }
- }
- break;
-
- case STARTA:
- deciph(IDE());
- if (debugf) printf(
- "At %6.2f # %2.0f starts work\n",
- T(), A(2));
- if (rewkn == 0) TALLY(statn, 1.0);
- busy[statn] = YES;
- SCHED(A(1), ENDACT, IDE());
- break;
-
- case ENDACT:
- deciph(IDE());
- TALLY(statn, 0.0);
- if (debugf) printf(
- "At %6.2f # %2.0f ends work",
- T(), A(2));
- busy[statn] = NO;
-
- if (RA() > defect[statn])
- {
- if (statn == FINAL)
- {
- DISPOS();
- if (debugf)
- printf(" and discharged\n");
- } else
-
- {
- SETA(1, RN(0.25, 0.05));
- SCHED(0, NEXTAC, statn + 1);
- if (debugf)
- printf(" and goes on\n");
- }
- } else
-
- {
- SETA(1, A(1)/2.0);
- SCHED(0.0, NEXTAC,
- statn + 4*(rewkn + 1));
- if (debugf)
- printf(" and recycled\n");
- }
-
- if (debugf) printf(
- "At %6.2f %d are waiting at %d\n",
- T(), NQ(statn), statn);
- if (NQ(statn)) triggr(statn);
- break;
- }
- } while(ecode);
-
- SUMRY("");
- }